package servlet.PropertyManagementModule.equipmentMaintenance;

import bean.dto.EquipmentPage;
import bean.pojo.Maintenance;
import bean.pojo.Medical;
import bean.vo.CostOption;
import com.alibaba.fastjson2.JSONObject;
import commons.baseServlet.BaseServlet;
import commons.format.NumberFormat;
import commons.r.R;
import commons.xlhUtils.MyFormatUtils;
import service.EquipmentMaintenanceService;
import service.MedicalAppointmentService;
import service.impl.EquipmentMaintenanceServiceImpl;
import service.impl.MedicalAppointmentServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;

/**
 * servlet.PropertyManagementModule.equipmentMaintenance
 * User: xlh
 * Date: 2024/12/20 10:08
 * motto:推到高塔
 * Description:
 * Version: V1.0
 */
@WebServlet(value = "/equipmentMaintenance/*")
public class EquipmentMaintenanceServlet  extends BaseServlet {
    public R findByPage(HttpServletRequest request){
        Integer page= NumberFormat.stringToInteger(request.getParameter("page"));
        Integer limit= NumberFormat.stringToInteger(request.getParameter("limit"));
        String selectMonth= request.getParameter("selectMonth");
        String selectedStatus= request.getParameter("selectedStatus");
        EquipmentMaintenanceService equipmentMaintenanceService=new EquipmentMaintenanceServiceImpl();
        EquipmentPage equipmentPage=new EquipmentPage();

        equipmentPage.setSelectMonth(selectMonth);
        equipmentPage.setSelectedStatus(selectedStatus);
        equipmentPage.setPage(page);
        equipmentPage.setLimit(limit);

        List<Maintenance> list = null;
        Long  total=equipmentMaintenanceService.findByTotal(equipmentPage);
        //当前页码的数据
        if(total>0) {
            //当前页码的数据
            list =equipmentMaintenanceService.findByPage(equipmentPage);
        }
        R r= R.ok().addData("total",total).addData("list",list);
        return r;
    }
    public R updatMaintenance(HttpServletRequest request){
        try {
            BufferedReader bufferedReader=request.getReader();
            String data=bufferedReader.readLine();
            Maintenance maintenance= JSONObject.parseObject(data,Maintenance.class);
            EquipmentMaintenanceService equipmentMaintenanceService=new EquipmentMaintenanceServiceImpl();
            boolean t=equipmentMaintenanceService.updatMaintenance(maintenance);
            return t?R.ok("修改成功"):R.ok("修改失败");
        } catch (
            IOException e) {
            e.printStackTrace();
        }
            return R.error("添加出错");
    }
}
